package com.yunji.ylexpiration.service.impl;

import com.yunji.ylexpiration.entity.FurnCommodity;
import com.yunji.ylexpiration.entity.FurnCommodityExample;
import com.yunji.ylexpiration.mapper.FurnCommodityMapper;
import com.yunji.ylexpiration.service.FurnCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FurnCommodityServiceImpl implements FurnCommodityService {

    @Autowired
    private FurnCommodityMapper furnCommodityMapper;

    @Override
    public List<FurnCommodity> selectByClassificationtype_idandLimit6(Integer [] classId) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByClassificationtype_idandLimit6(classId);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> selectById() {
        FurnCommodityExample example = new FurnCommodityExample();
        FurnCommodityExample.Criteria criteria = example.createCriteria();
        criteria.andClassificationtypeIdEqualTo(6);
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByExample(example);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> selectByClassificationtype_parent_idandLimit16(Integer[] classId2) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByClassificationtype_parent_idandLimit16(classId2);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> selectById2() {
        FurnCommodityExample example = new FurnCommodityExample();
        FurnCommodityExample.Criteria criteria = example.createCriteria();
        criteria.andClassificationtypeParentIdEqualTo(3);
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByExample(example);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> selectByClassificationtype_parent_id(Integer snum,Integer price, String typename,String typename2,Integer pagenum,Integer pagecount) {
        if(snum==null){
            snum = 0;
        }
        if(price==null){
            price = 0;
        }
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByClassificationtype_parent_id(snum,price,typename,typename2,pagenum,pagecount);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> CountByClassificationtype_parent_id(String typename,String typename2) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.CountByClassificationtype_parent_id(typename,typename2);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> selectByClassId(String typename,Integer [] classId3) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByClassId(typename,classId3);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> searchByProductName(Integer snum, Integer price, String productname,String productname2,String productname3 ,Integer pagenum, Integer pagecount) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.searchByProductName(snum, price, productname,productname2,productname3, pagenum, pagecount);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> SearchByCount(String productname,String productname2,String productname3) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.SearchByCount(productname,productname2,productname3);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public FurnCommodity selectByid(Integer comid) {
        if (null == comid){
            return null;
        }
       FurnCommodityExample example=new FurnCommodityExample ();
        FurnCommodityExample.Criteria criteria = example.createCriteria ();
        criteria.andIdEqualTo (comid);
        List<FurnCommodity> furnCommodity1 = furnCommodityMapper.selectByExample (example);
        if (furnCommodity1.size ()>1){
            return null;
        }
        return furnCommodity1.get (0);
    }

    @Override
    public FurnCommodity selectDetailById(Integer id) {
        FurnCommodityExample example = new FurnCommodityExample();
        FurnCommodityExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByExample(example);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities.get(0);
    }

    @Override
    public List<FurnCommodity> recommendByfirve(Integer ClassId, Integer ParentId) {
        FurnCommodityExample example = new FurnCommodityExample();
        FurnCommodityExample.Criteria criteria = example.createCriteria();
        criteria.andClassificationtypeIdEqualTo(ClassId);
        criteria.andClassificationtypeParentIdEqualTo(ParentId);
        List<FurnCommodity> furnCommodities = furnCommodityMapper.selectByExample(example);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }
        return furnCommodities;
    }

    @Override
    public List<FurnCommodity> RelatedByLimit15(Integer ClassId,Integer ParentId,Integer pagenum,Integer pagecount) {
        List<FurnCommodity> furnCommodities = furnCommodityMapper.RelatedByLimit15(ClassId, ParentId,pagenum,pagecount);
        if(furnCommodities==null||furnCommodities.size()==0){
            return null;
        }

        return furnCommodities;
    }
}
